package Accessors;

import java.io.IOException;

import utils.RESTfulConnect;
import utils.URLTools;
import android.content.Context;
import android.os.AsyncTask;

public class GCMAccessor {
	private final String NAME = "gcm";
	private final String DIALOG = "Adding GCM Id...";
	
	public void addID(final String id, final Context context){
		String dialog = DIALOG;
		String rfString = NAME + "/addId/" + id;
		getItem(context, dialog, rfString);
	}
	
	public void getItem(final Context context, final String dialog, final String str){
		final String strStart = URLTools.getURLString(context);
		new DownloadItemTask().execute(strStart+str, URLTools.getUSERString(context), URLTools.getPASSString(context));
	}
	
	private class DownloadItemTask extends AsyncTask<String, Void, String> {
    	@Override
        protected String doInBackground(String... urls) {

            try {
                return RESTfulConnect.getResource(urls[0], urls[1], urls[2]);
            } catch (IOException e) {
            	e.printStackTrace();
            	return "Connection Error";
            }
        }
		@Override
        protected void onPostExecute(String result) {
        }
    }

}
